Skip to content

Conversation

qstyler
Copy link

@qstyler qstyler commented Dec 9, 2022

…param

Allows @Crud decorator accept loadRelationIds query param that is later accepted by TypeORM.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • The commit message was generated by yarn commit

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] Tests
[ ] Release
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behaviour?

Introduces loadRelationIds, a new field in QueryOptions. That is passed to TypeORM.

This allows the loading of relations ids in objects without joining the whole table.

For example this controller:

@Crud({
  model: { type: UserLicense },
  query: {
    loadRelationIds: {
      relations: ['license'],
      disableMixedMap: true,
    },
  },
})
@Controller('user.licenses')
class UserLicenseController {
  constructor(public service: UserLicenseService) {}
}

getting all records will return this:

[
  {
    "userId": 1,
    "licenseId": 1,
    "yearsActive": 3,
    "license": {
      "id": 1
    }
  },
  {
    "userId": 1,
    "licenseId": 2,
    "yearsActive": 5,
    "license": {
      "id": 2
    }
  },
  {
    "userId": 1,
    "licenseId": 4,
    "yearsActive": 7,
    "license": {
      "id": 4
    }
  },
  {
    "userId": 2,
    "licenseId": 5,
    "yearsActive": 1,
    "license": {
      "id": 5
    }
  }
]

This is very useful for building rest APIs without @RelationId() and @Column() hacks.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

…param

Allows `@Crud` decorator accept `loadRelationIds` query param that is later accepted by TypeORM.
@afilp
Copy link

afilp commented Nov 1, 2023

@qstyler This repo seems to not be supported anymore, would you like to submit your PR to this forked repo, which is more up-to-date? Thanks!

https://github.com/gid-oss/dataui-nestjs-crud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants